Skip to content

Conversation

@Earlopain
Copy link
Contributor

In Ruby 3.5, most of the cgi gem is removed. That includes CGI.parse, which rouge uses.

But, we can subsistute it with URI.decode_www_form. The data is returned in a slightly different format (array of arrays instead of a hash), so do some processing to get back into the expected structure.

https://bugs.ruby-lang.org/issues/21258

In Ruby 3.5, most of the cgi gem is removed. That includes `CGI.parse`, which `rouge` uses.

But, we can subsistute it with `URI.decode_www_form`.
The data is returned in a slightly different format (array of arrays instead of a hash),
so do some processing to get back into the expected structure.

https://bugs.ruby-lang.org/issues/21258
javierjulio added a commit to javierjulio/envied that referenced this pull request Jun 6, 2025
In Ruby 3.5, most of the cgi gem is removed which includes `CGI.parse`. We can replace this with `URI.decode_www_form` but it has some slight differences. Seems any blank value now always comes back as nil rather nil or an empty string depending so this can be a breaking change.

rouge-ruby/rouge#2131
javierjulio added a commit to javierjulio/envied that referenced this pull request Jun 6, 2025
* Replace CGI with URI for Ruby 3.5 support

In Ruby 3.5, most of the cgi gem is removed which includes `CGI.parse`. We can replace this with `URI.decode_www_form` but it has some slight differences. Seems any blank value now always comes back as nil rather nil or an empty string depending so this can be a breaking change.

rouge-ruby/rouge#2131

* Update CHANGELOG.md
@tancnle tancnle self-requested a review June 24, 2025 14:10
@yahonda
Copy link

yahonda commented Aug 14, 2025

It would be great if someone could review this pull request because Rails CI started failing https://buildkite.com/rails/rails-nightly/builds/2679#0198a53d-2b95-4767-95aa-e54f1297493d/1193-1197 and this should resolve it.

yahonda added a commit to yahonda/rails that referenced this pull request Aug 14, 2025
This commit addresses this Rails CI Nightly failure below.
https://buildkite.com/rails/rails-nightly/builds/2679#0198a53d-2b95-4767-95aa-e54f1297493d/1193-1197

- Errors addressed by this commit

```
$ ruby -v
ruby 3.5.0dev (2025-08-12T14:43:46Z master c5c894c6e4) +PRISM [x86_64-linux]
$ cd guides
$ bundle install
$ bundle exec rake guides:lint
... snip ...
Generating active_record_validations.md as active_record_validations.html
Generating 5_1_release_notes.md as 5_1_release_notes.html
Generating asset_pipeline.md as asset_pipeline.html
/home/yahonda/.local/share/mise/installs/ruby/trunk/lib/ruby/gems/3.5.0+2/gems/rouge-4.5.1/lib/rouge/lexer.rb:55:in 'Rouge::Lexer.lookup_fancy': undefined method 'parse' for class CGI (NoMethodError)

        opts = CGI.parse(opts || '').map do |k, vals|
                  ^^^^^^
	from /home/yahonda/.local/share/mise/installs/ruby/trunk/lib/ruby/gems/3.5.0+2/gems/rouge-4.5.1/lib/rouge/lexer.rb:95:in 'Rouge::Lexer.find_fancy'
	from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/markdown/renderer.rb:35:in 'RailsGuides::Markdown::Renderer#block_code'
	from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/markdown.rb:90:in 'Redcarpet::Markdown#render'
	from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/markdown.rb:90:in 'RailsGuides::Markdown#generate_body'
	from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/markdown.rb:28:in 'RailsGuides::Markdown#render'
	from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/generator.rb:214:in 'RailsGuides::Generator#generate_guide'
	from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/generator.rb:108:in 'block in RailsGuides::Generator#generate_guides'
	from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/generator.rb:106:in 'Array#each'
	from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/generator.rb:106:in 'RailsGuides::Generator#generate_guides'
	from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/generator.rb:52:in 'RailsGuides::Generator#generate'
	from rails_guides.rb:31:in '<main>'
rake aborted!
Command failed with status (1): [/home/yahonda/.local/share/mise/installs/ruby/trunk/bin/ruby -Eutf-8:utf-8 rails_guides.rb]
/home/yahonda/src/github.com/rails/rails/guides/Rakefile:33:in 'block (3 levels) in <top (required)>'
/home/yahonda/.local/share/mise/installs/ruby/trunk/bin/bundle:25:in '<main>'
Tasks: TOP => guides:lint => guides:lint:check_links
(See full trace by running task with --trace)
$
```

This workaround commit can be reverted when newer version of rouge gem
is relased including rouge-ruby/rouge#2131

- Ruby 3.5 removes cgi by default
https://bugs.ruby-lang.org/issues/21258
ruby/ruby#13275
@jneen
Copy link
Member

jneen commented Aug 14, 2025

@tancnle if gitlab doesn't currently have the capacity to maintain this gem, I should mention I am open for contracting work and am happy to put in some hours to get it back on track.

@tancnle
Copy link
Collaborator

tancnle commented Aug 18, 2025

The MR LGTM! We would need to add ruby-head to our CI at some point.

@tancnle tancnle added this pull request to the merge queue Aug 18, 2025
Merged via the queue into rouge-ruby:master with commit a59d414 Aug 18, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants